
import 'package:get/get.dart';
import 'package:jiffy/jiffy.dart';
import 'package:safetymonitor/app/core/http/http.dart';
import 'package:safetymonitor/app/core/utils/interface.dart';
import 'package:safetymonitor/app/data/entities/home/monitor/person_monitoring_page_entity_entity.dart';

class PersonnelMonitoringController extends GetxController  {
   List<PersonMonitoringPageEntityEntity> tableDataS=[];
  final List<List<String>> tableData = [
    // ['人员单位', '人员姓名', '人员分组', '人员工种', '进场时间', '出场时间'],
    //   ['XXX单位', '车小组', '这是分组', '电焊', '1/14 10:00:00', '1/14 10:00:00'],
  ];
  @override
  void onInit() {
    super.onInit();
    //获得人员实时监测分页
    personMonitoring();
  }

  ///获得人员实时监测分页
  void personMonitoring() async {
    tableDataS.clear();
    tableData.clear();
    tableData.add(['序号','人员单位', '人员姓名', '人员分组', '人员工种', '进场时间', '出场时间']);
    final res = await HttpUtil().generateGetRequest<List<PersonMonitoringPageEntityEntity>>(
      Interface.realtimePersonMonitoring,
      queryParameters: {
        // 'pageNo': 1,
        // 'pageSize': 10,
      },
    ).execute();
    res.onSuccess((result) {
      if (result.data != null) {
       tableDataS = result.data ?? [];
        for (int i=0;i<tableDataS.length;i++ ) {
        // for (PersonMonitoringPageEntityEntity data in tableDataS) {
          final List<String> sub = [
            '$i',
            tableDataS[i].companyName ?? '',
            tableDataS[i].name ?? '',
            tableDataS[i].groupId ?? '',
            tableDataS[i].craftStr ?? '',
            int.parse( tableDataS[i].enterTime ?? '0')!=0? Jiffy.parseFromMillisecondsSinceEpoch(int.parse( tableDataS[i].enterTime ?? '0')).format(pattern: 'yyyy-MM-dd HH:mm:ss'):'',
            int.parse( tableDataS[i].exitTime ?? '0')!=0?Jiffy.parseFromMillisecondsSinceEpoch(int.parse( tableDataS[i].exitTime ?? '0')).format(pattern: 'yyyy-MM-dd HH:mm:ss'):'',
          ];
          tableData.add(sub);
        }
        if(tableDataS.isEmpty){
          tableData.clear();
        }
      }
    });
    update();
  }

}
